﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Validity.Test.Constraints.ObjectConstraints
{
  [TestClass]
  public class IsSameAsConstraintTest
    : ConstraintTestBase<ObjectStub>
  {
    public class Validator
      : ValidatorBase<ObjectStub>
    {
      public Validator()
      {
        DefineRulesFor(ctx => ctx.MyObjectProperty1).IsSameAs(ReferenceValue);
        DefineRulesFor(ctx => ctx.MyObjectProperty2).IsSameAs(() => ReferenceValue);
        DefineRulesFor(ctx => ctx.MyObjectProperty3).IsSameAs(obj => ReferenceValue);
      }
    }

    private static readonly Object ReferenceValue = new Object();

    public IsSameAsConstraintTest() : base(new Validator(), 3) { }

    [TestMethod]
    public void TestConstraintVerified()
    {
      ValidateConstraintVerfied(CreateContext(ReferenceValue));
    }

    [TestMethod]
    public void TestConstraintViolated()
    {
      const String ruleViolation = "Must be the same 'System.Object'";

      ValidateConstraintViolated(CreateContext(new Object()), ruleViolation);
    }

    public ObjectStub CreateContext(Object value)
    {
      var result = new ObjectStub();

      result.MyObjectProperty1 = value;
      result.MyObjectProperty2 = value;
      result.MyObjectProperty3 = value;

      return result;
    }
  }
}
